
import time
import datetime

"""Indicates that a load is starting."""
START_LOAD = 'start_load'

"""Indicates that a load failed due to bad credentials."""
CREDENTIAL_FAIL = 'credential_failure'

"""Indicates that a load succeeded."""
SUCCESS = 'success'

"""Indicates the next time a scrape is scheduled to run."""
SCHEDULE_NEXT = 'scheduled_next'

class Log:
    """Responsible for storing the current log state. Events in a related set can be grouped together by giving them a family."""

    def __init__(self, gm):
        self.__gm = gm

    def make_family(self):
        """Return a token that indicates a run. Allows a series of events to be tied together."""
        return time.time()

    def log(self, family, event_type, description=""):
        """Log the given event."""
        f = open(self.__gm.get_home() + 'events.txt', 'a+')
        try:
            f.write("%s - \"%s\" - %s: %s\n" % (family, datetime.datetime.now(), event_type, description))
        finally:
            f.close()


class NullLog(Log):
    
    def __init__(self): 
        pass

    def log(self, family, event_type, description):
        pass
